package com.lihegang.example.component;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wujing
 */
@Component
public class RoncooAmqpComponent {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send(String msg) {
        this.amqpTemplate.convertAndSend("rabbit.queue", msg);
    }

    public void sendTopic(String msg){
        amqpTemplate.convertAndSend("topic_exchange","topic_key1",msg + 1);
    }

    @RabbitListener(queues = "rabbit.queue")
    public void receiveQueue(String text) {
        System.out.println("接受到：" + text);
    }

}